package com.glg.book.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/login")
    public String login(String userName, String password, HttpSession session) {
        //1. 校验参数
        //2. 验证密码是否正确
        //3. 如果正确，则返回对应结果
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) {
            return "用户名或密码为空";
        }
        //理论上应该从数据库中读取，但是当前还未学习，先模拟校验
        if(!"admin".equals(userName) || !"admin".equals(password)){
            //错误的情况
            return "密码错误";
        }

        session.setAttribute("userName",userName);
        return "";
    }
}
